package com.qianying.controller.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qianying.comment.CommonResult;
import com.qianying.entity.OrderType;
import com.qianying.service.OrderTypeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 订单类型Controller
 */
@RestController
@RequestMapping("/admin/orderType")
@Tag(name = "平台设置：订单类型管理", description = "订单类型信息的增删改查接口")
public class OrderTypeController {

    @Autowired
    private OrderTypeService orderTypeService;

    /**
     * 分页查询订单类型列表
     */
    @GetMapping("/getPage")
    @Operation(
            summary = "分页查询订单类型列表",
            description = "支持按订单类型名称模糊查询，返回分页数据",
            parameters = {
                    @Parameter(name = "current", description = "页码", example = "1"),
                    @Parameter(name = "size", description = "每页条数", example = "10"),
                    @Parameter(name = "orderTypeName", description = "订单类型名称（模糊查询）", example = "标准订单")
            }
    )
    public CommonResult<IPage<OrderType>> getPage(
            @RequestParam(defaultValue = "1") Integer current,
            @RequestParam(defaultValue = "10") Integer size,
            @RequestParam(required = false) String orderTypeName) {
        Page<OrderType> page = new Page<>(current, size);
        return orderTypeService.getPage(page, orderTypeName);
    }

    /**
     * 根据ID查询订单类型
     */
    @GetMapping("/getById")
    @Operation(
            summary = "查询订单类型详情",
            description = "通过ID获取订单类型的完整信息",
            parameters = {
                    @Parameter(name = "id", description = "主键ID", required = true, example = "1")
            }
    )
    public CommonResult<OrderType> getById(@RequestParam Long id) {
        return orderTypeService.getById(id);
    }

    /**
     * 新增订单类型
     */
    @PostMapping("/saveType")
    @Operation(
            summary = "新增订单类型",
            description = "创建新的订单类型记录，订单类型名称和代号为必填项",
            parameters = {
                    @Parameter(name = "orderTypeName", description = "订单类型名称", required = true, example = "标准订单"),
                    @Parameter(name = "orderTypeCode", description = "订单类型代号", required = true, example = "ST"),
                    @Parameter(name = "description", description = "订单类型说明", example = "常规的产品购买订单")
            }
    )
    public CommonResult<?> saveType(@RequestBody OrderType orderType) {
        return orderTypeService.saveType(orderType);
    }

    /**
     * 更新订单类型
     */
    @PostMapping("/updateType")
    @Operation(
            summary = "更新订单类型",
            description = "修改已有订单类型信息，必须包含ID、订单类型名称和代号",
            parameters = {
                    @Parameter(name = "id", description = "主键ID", required = true, example = "1"),
                    @Parameter(name = "orderTypeName", description = "订单类型名称", required = true, example = "标准订单"),
                    @Parameter(name = "orderTypeCode", description = "订单类型代号", required = true, example = "ST"),
                    @Parameter(name = "description", description = "订单类型说明", example = "常规的产品购买订单")
            }
    )
    public CommonResult<?> updateType(@RequestBody OrderType orderType) {
        return orderTypeService.updateType(orderType);
    }

    /**
     * 删除订单类型
     */
    @PostMapping("/removeById")
    @Operation(
            summary = "删除订单类型",
            description = "通过ID删除指定的订单类型记录",
            parameters = {
                    @Parameter(name = "id", description = "主键ID", required = true, example = "1")
            }
    )
    public CommonResult<?> removeById(@RequestParam Long id) {
        return orderTypeService.removeById(id);
    }

    /**
     * 查询所有订单类型（不分页）
     */
    @GetMapping("/getAll")
    @Operation(
            summary = "查询所有订单类型",
            description = "返回所有订单类型列表，适用于下拉选择等场景",
            parameters = {}
    )
    public CommonResult<java.util.List<OrderType>> getAll() {
        return orderTypeService.getAll();
    }
}
